function showTips(spanID,msg){

    var span = document.getElementById(spanID)
    span.innerHTML = msg
}
function checkUsername(){
    var uValue = document.getElementById("username").value
    var span = document.getElementById("span_username")
    if(uValue.length<6){
        span.innerHTML = "<font color='red' size='2'>Username is too short</font>"
        return false
    }else{
        span.innerHTML = "<font color='red' size='2'>Available</font>"
        return true
    }
}
function checkPhone(){
    var uValue = document.getElementById("phone").value
    var span = document.getElementById("span_phone")
    if(uValue.length!=11){
        span.innerHTML = "<font color='red' size='2'>Phone number is not available</font>"
        return false
    }else{
        span.innerHTML = "<font color='red' size='2'>Available</font>"
        return true
    }
}
function checkPassword(){
    var uPass = document.getElementById("password").value
    var span = document.getElementById("span_password")
    if(uPass.length<6){
        span.innerHTML = "<font color='red' size='2'>too short</font>"
        return false
    }else{
        span.innerHTML = "<font color='red' size='2'>Available</font>"
        return true
    }
}

function checkRePassword(){
    var uPass = document.getElementById("password").value
    var uRePass = document.getElementById("repassword").value

    var span = document.getElementById("span_repassword")

    if(uPass!=uRePass){
        span.innerHTML = "<font color='red' size='2'>Passwords are inconsistent</font>"
        return false
    }else{
        span.innerHTML = "<font color='red' size='2'>Passwords are consistent</font>"
        return true
    }
}

function checkMail(){

    var umail = document.getElementById("email").value
    var span = document.getElementById("span_email")
    if(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(umail)){
        span.innerHTML = "<font color='red' size='2'>邮箱可用</font>"
        return true
    }else{
        span.innerHTML = "<font color='red' size='2'>不可用</font>"
        return false
    }

}

function checkForm(){
    var flag = checkMail()&&checkPassword()&&checkRePassword()&&checkUsername();
    return flag;
}
